package com.example.java_gobang2.mapper;

import com.example.java_gobang2.model.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {
    @Insert("insert into user(username,password,score,totalCount,winCount) values (#{username},#{password},1000,0,0)")
    public Integer insertUser(User user);

    @Select("select * from user where userId = #{userId};")
    public User selectByUserId(int userId);
    @Select("select * from user where username = #{username};")
    public User selectByUsername(String username);

    @Update("update user set winCount = winCount+1,totalCount = totalCount+1,score = score+10 " +
            "where userId = #{userId}")
    public void updateWin(int userId);

    @Update("update user set totalCount = totalCount+1,score = score-10 " +
            "where userId = #{userId}")
    public void updateLose(int userId);


    List<User> selectUserRank();
}